#include<bits/stdc++.h>
using namespace std;
const int N=27;
int a[N],t,n,sum,ans,lst0,lst1;
void Files(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
}
int main(){
    Files();
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n),memset(a,0,sizeof(a)),ans=0;
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=0;i<(1<<n);i++){
            sum=lst0=lst1=0;
            for(int j=1;j<=n;j++){
                if(i&(1<<j-1)) sum+=(lst1&&a[j]==a[lst1])*a[j],lst1=j;
                else sum+=(lst0&&a[j]==a[lst0])*a[j],lst0=j;
            }
            ans=max(ans,sum);
        }
        printf("%d\n",ans);
    }
    return 0;
}
